package com.wiz.weixin.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

public class MapUtil {
	public static void main(String[] args) {
			System.out.println(MapUtil.appendUrl("104.050209","30.679445","我家",
					 "104.071086","30.581723","公司","成都"));
	}
	public static String appendUrl(String latitude,String longitude,String startsName,
			String endLatitude,String endLongitude,String endName,String city){
		  StringBuffer sb = new StringBuffer();  
		  try {
		    sb.append("http://api.map.baidu.com/direction?origin=latlng:")  
		            // 我的位置  
		            .append(latitude)  
		            .append(",")  
		            .append(longitude)  
		            .append("|name:")  
		            .append(URLEncoder.encode(startsName, "UTF-8").toString())  
		            // 去的位置  
		            .append("&destination=latlng:")  
		            .append(endLatitude)  
		            .append(",")  
		            .append(endLongitude)  
		            .append("|name:")  
		            .append(URLEncoder.encode(endName, "UTF-8").toString().replaceAll("nbsp;|&", ""))  
		            // 城市  
		            .append("&mode=driving®ion=").append(URLEncoder.encode(city, "UTF-8").toString())  
		            .append("&output=html"); 
		  } catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		    return sb.toString();
	}
}
